/*
 * MonitorModule.h
 *
 *  Created on: 2009-10-29
 *      Author: jychen
 */

#ifndef MONITORMODULE_H_
#define MONITORMODULE_H_

#include <sys/types.h>
#include <unistd.h>

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

//Socket
#include "../Socket/jssocket.h"
#include "../Socket/jsiomodel.h"
#include "../Packets/jsmsg.h"

#include "../Public/public.h"

#include <iostream>
using namespace std;

#define ATM_PATH        "atm" //文件名的路径
#define ATM_BIN         "atm"

CJSIOModel g_IOModule;
int g_nUdpFd = -1;


//局限性
//模块ID必须从1开始，顺序加1递增
//Monitor模块ID必须=1

typedef struct
{
	time_t s;	//send
	time_t r;	//recv
	int nCount;
	bool bHasSend;
	pid_t pid;
}MonitorInfo;

//这里有一个对应关系，monitor[N-1]--模块ID为N的监视信息
MonitorInfo monitor[MODNUM];

void InitMonitorInfo();

int RunAllModule();
int RunModule(int modID);

int CallBack_UDP(int nFd, int event, void* param);
int ReadMsg_UDP(int nFd);


//=========monitor=============begin
int HelloMsgHandle(int modID, CJSMsg &msg);

int SendHelloToAllModule();
int SendHello(int nFd, int modID);

//监视函数，根据模块ID，决定监视哪个模块
int ModuleMonitor(int modID);
int MonitorAllModule();

//启动一路线程，监视其它模块
void* MonitorThread(void*);
//=========monitor==============end


#endif /* MONITORMODULE_H_ */
